//https://leetcode.cn/problems/binary-tree-right-side-view/solutions/213494/er-cha-shu-de-you-shi-tu-by-leetcode-solution/
//感觉这个答案不太对啊！
#include <iostream>
#include <vector>
using namespace std;

class Solution { //先层序遍历，然后取每层最后一个作为右视图
public:
    vector<int> rightSideView(TreeNode* root) {
        vector<int> res;
        queue<TreeNode*> q;
        q.push(root);
        while(!q.empty()){
            int size = q.size();
             while(size--){
                TreeNode* node = q.front();
                q.pop();
                if(size == 0 && node)
                    res.push_back(node->val);
                if(node && node->left)
                    q.push(node->left);
                if(node && node->right)
                    q.push(node->right);
            }
      }
    return res;
    }
};